﻿using System;
using System.Collections;
using Manager;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

// Token: 0x02000340 RID: 832
public class LoadVoice : LoadAudioBase
{
	// Token: 0x06001511 RID: 5393 RVA: 0x00090A30 File Offset: 0x0008EC30
	public override IEnumerator _Init()
	{
		if (base.initialized)
		{
			yield break;
		}
		if (this.isAsync)
		{
			yield return base.StartCoroutine(base._Init());
		}
		else
		{
			base.StartCoroutine(base._Init());
		}
		if (base.clip == null)
		{
			yield break;
		}
		Singleton<Voice>.Instance.Bind(this);
		base.name = "Voice LoadEnd";
		if (base.audioSource == null)
		{
			GlobalData.Debug_LogError("AudioSource none\nVoice No:" + this.no);
			UnityEngine.Object.Destroy(base.gameObject);
			yield break;
		}
		if (this.settingNo < 0)
		{
			base.audioSource.loop = !this.isPlayEndDelete;
			base.audioSource.spatialBlend = (float)((!(this.voiceTrans != null)) ? 0 : 1);
		}
		base.audioSource.pitch = this.pitch;
		yield break;
	}

	// Token: 0x06001512 RID: 5394 RVA: 0x00090A4C File Offset: 0x0008EC4C
	protected override IEnumerator Start()
	{
		base.enabled = false;
		if (base.audioSource == null)
		{
			yield return base.StartCoroutine(this._Init());
		}
		while (!base.isLoadEnd)
		{
			yield return null;
		}
		if (base.clip == null)
		{
			yield break;
		}
		base.StartCoroutine(base.Play(null, null));
		if (this.voiceTrans == null)
		{
			yield break;
		}
		Transform audioTrans = base.audioSource.transform;
		this.UpdateAsObservable().TakeUntilDestroy(this.voiceTrans).Subscribe(delegate(Unit _)
		{
			audioTrans.position = this.voiceTrans.position;
			audioTrans.rotation = this.voiceTrans.rotation;
		});
		base.enabled = true;
		yield break;
	}

	// Token: 0x04001957 RID: 6487
	public int no;

	// Token: 0x04001958 RID: 6488
	public Transform voiceTrans;

	// Token: 0x04001959 RID: 6489
	public Voice.Type type;

	// Token: 0x0400195A RID: 6490
	public bool isPlayEndDelete = true;

	// Token: 0x0400195B RID: 6491
	public float pitch = 1f;
}
